<template>
  <a-modal
    title="扣佣金"
    :visible="visible"
    @ok="onSubmit"
    @cancel="visible = false"
  >
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="{ span: 6 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-model-item label="金额" prop="draw">
        <a-input-number
          class="w-32"
          v-model="form.coins"
          :max="max"
          :min="0"
          :step="0.001"
        />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      visible: false,
      id: null,
      max: 0,
      form: {
        coins: 0,
      },
      rules: {
        coins: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  computed: {
    ...mapGetters('account', ['sys']),
  },
  methods: {
    show(row) {
      this.id = row.id
      this.max = row.coins
      this.visible = true
    },
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (this.form.coins == 0) {
          return
        }
        if (valid) {
          //   console.log(this.form)
          this.axios
            .post(`/a/agents/${this.id}/draw-coins`, this.form)
            .then((res) => {
              this.visible = false
              this.form = this.$options.data().form
              this.$message.success('操作成功')
              this.$emit('refresh')
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  },
}
</script>
